Attribute VB_Name = "modValidation"
Option Explicit

Public Function ValidKeys(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer

'ex:  KeyAscii = ValidKeys(KeyAscii, "01234567890.", True)
Dim ValidateList As String
Dim KeyOut As Integer

    If KeyIn = 13 Then Exit Function
    
    If Editable = True Then
        ValidateList = UCase(ValidateString) & Chr(8)
    Else
        ValidateList = UCase(ValidateString)
    End If
    
    If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
        KeyOut = KeyIn
    Else
        KeyOut = 0
        Beep
    End If
    
    ValidKeys = KeyOut
End Function

Public Function InvalidKeys(KeyAscii As Integer, varStr As String) As Integer
    If varStr Like ("*" & Chr(KeyAscii) & "*") Then
        InvalidKeys = 0
    Else: InvalidKeys = KeyAscii
    End If
End Function

'Sends the cursor to the next tab stop
Public Sub SendKeysTab(Key As Integer)
    If Key = 13 Then SendKeys "{Tab}"
End Sub



'Audit trail function
Function UpdateLogFile(cModule As String, cTranNo As String, cEvent As String)
On Error Resume Next
    Dim LogCmd As ADODB.Command
    Set LogCmd = New ADODB.Command
    With LogCmd
        Set .ActiveConnection = cn
        .CommandText = "AuditTrail"
        .CommandType = adCmdStoredProc
        .Parameters.Refresh
    End With
    LogCmd.Parameters("@cModule") = LTrim(RTrim(cModule))
    LogCmd.Parameters("@cTranNo") = LTrim(RTrim(cTranNo))
    LogCmd.Parameters("@cEvent") = LTrim(RTrim(cEvent))
    LogCmd.Parameters("@cUser") = LTrim(RTrim(SecUserID))
    LogCmd.Parameters("@cCompanyID") = LTrim(RTrim(COID))
    LogCmd.Execute
    Set LogCmd.ActiveConnection = Nothing
End Function

'Gl Activity
Public Function UpdateGLA(cEvent As String, cModule As String, cTranNo As String)
On Error Resume Next
Dim LogCmd As ADODB.Command
Set LogCmd = New ADODB.Command
    With LogCmd
        Set .ActiveConnection = cn
        If cEvent = "Update" Then
            .CommandText = "USP_UpdateGL"
        Else: .CommandText = "USP_DeleteGL"
        End If
        .CommandType = adCmdStoredProc
        .Parameters.Refresh
    End With
    LogCmd.Parameters("@cCompanyID") = LTrim(RTrim(COID))
    LogCmd.Parameters("@cModule") = LTrim(RTrim(cModule))
    LogCmd.Parameters("@cTranNo") = LTrim(RTrim(cTranNo))
    
    LogCmd.Execute
    Set LogCmd.ActiveConnection = Nothing
End Function

'FixedLength
Public Function FixedLength(KeyAscii As Integer, sText As String, nLength As Long) As Integer
    If KeyAscii = vbKeyReturn Then
        FixedLength = KeyAscii
    ElseIf KeyAscii = vbKeyDelete Then
        FixedLength = KeyAscii
    ElseIf KeyAscii = vbKeyBack Then
        FixedLength = KeyAscii
    ElseIf Len(sText) = nLength Then
        Beep
        FixedLength = 0
    Else
        FixedLength = KeyAscii
    End If
End Function

'Passing string value to variable 'sFilterString'
'Public Sub sFilterString =(str As String)
'    If Trim(str) <> "" Then
'        sFilterString = Trim(str)
'    Else
'        sFilterString = ""
'    End If
'End Sub

